/*


 */

package jas.http.response;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLConnection;
import java.util.Date;

/**
 *
 *
 */
public class FileResponseBody implements ResponseBody {
    
    private File file;
    
    public FileResponseBody(File file) {
        this.file = file;
    }
    
    public void print(OutputStream output) throws IOException {
        InputStream input = null;
        try {
            input = new FileInputStream(file);
            int data;
            while ((data = input.read()) != -1) {
                output.write(data);
            }
        } finally {
            if (input != null) {
                input.close();
            }
        }
    }
    
    public long getContentLength() {
        return file.length();
    }
    
    public String getContentType() {
        return URLConnection.guessContentTypeFromName(file.getName());
    }

    public String getContentEncoding() {
        return "";
    }

    public Date getModifiedDate() {
        return new Date(file.lastModified());
    }
    
}
